<?php
namespace app\index\controller;
use think\Request;
use think\controller\Rest;
class Apply extends Rest{
    public function getApply(){
        $model = model('Apply');
        $data['openid']=input('param.openid');
        // $data=$model->where($data)
        //     ->field('tianjiao_goods.name as gname,tianjiao_apply.*')
        //     ->join('tianjiao_goods on tianjiao_apply.goodsid=tianjiao_goods.id','LEFT')->select();
        $res=$model->where($data)->alias('apply')
             ->join('tianjiao_goods b', 'apply.goodsid =b.id')
             ->field('b.name as gname,apply.*')
             ->select();
        return json($res);
    }
    public function add(){
        $model = model('Apply');
    	$data['phone']=input('param.phone');
    	$data['name']=input('param.name');
        $data['time']=input('param.time');
    	$data['openid']=input('param.openid');
        $data['gender']=input('param.gender');
        $goodsList=json_decode(input('param.goods'),true);
        foreach ($goodsList as $key => $value) {
            // var_dump($value['Id']);
            $data['goodsid']=$value['Id'];
            $data['num']=$value['num'];
            $res=$model->insert($data);
        }
        return json($res);
    }
}